
using System;
using System.Data;
using System.Data.OleDb;
using System.Collections.Generic;

namespace Common
{
    /// <summary>
    /// Description of TCMDao.
    /// </summary>
    public class TCMDao
    {
        private TCMDao()
        {
        }

        public static int insert(TCM t)
        {
            string sql = "insert into tcm(patient_id,create_date)values(?,?);";
            OleDbParameter[] parameters = new OleDbParameter[2];
            parameters[0] = new OleDbParameter("@patient_id", OleDbType.Integer);
            parameters[0].Value = t.PatientId;
            parameters[1] = new OleDbParameter("@create_date", OleDbType.Date, 50);
            parameters[1].Value = t.CreateDate;
          

            return AccessDBUtil.ExecuteInsert(sql, parameters);
        }

        public static int deleteById(int id)
        {
            string sql = "delete from tcm where id=?";
            OleDbParameter[] parameters = new OleDbParameter[1];
            parameters[0] = new OleDbParameter("@id", OleDbType.Integer);
            parameters[0].Value = id;
            return AccessDBUtil.ExecuteNonQuery(sql, parameters);
        }

        public static int update(TCM t)
        {

            string sql = "update tcm set patient_id=?,create_date=?,syndrome1=?,syndrome2=?,syndrome3=?,syndrome4=?,syndrome5=?,syndrome6=?,syndrome7=?,syndrome8=?,syndrome9=?,syndrome10=?,syndrome11=?,syndrome12=?,syndrome13=?,syndrome14=?,syndrome15=?,syndrome16=?,syndrome17=?,syndrome18=?,syndrome19=?,syndrome20=?,syndrome21=?,syndrome22=?,syndrome23=?,syndrome24=?,syndrome25=?,syndrome26=?,syndrome27=?,syndrome28=?,syndrome29=?,syndrome30=?,tongue1=?,tongue2=?,tongue3=?,pulse=?,differentiation=?,conclusion=? where id=?;";
            OleDbParameter[] parameters = new OleDbParameter[39];
            parameters[0] = new OleDbParameter("@patient_id", OleDbType.Integer);
            parameters[0].Value = t.PatientId;
            parameters[1] = new OleDbParameter("@create_date", OleDbType.Date, 50);
            parameters[1].Value = t.CreateDate;
            parameters[2] = new OleDbParameter("@syndrome1", OleDbType.VarChar, 50);
            parameters[2].Value = t.Syndrome1;
            parameters[3] = new OleDbParameter("@syndrome2", OleDbType.VarChar, 50);
            parameters[3].Value = t.Syndrome2;
            parameters[4] = new OleDbParameter("@syndrome3", OleDbType.VarChar, 50);
            parameters[4].Value = t.Syndrome3;
            parameters[5] = new OleDbParameter("@syndrome4", OleDbType.VarChar, 50);
            parameters[5].Value = t.Syndrome4;
            parameters[6] = new OleDbParameter("@syndrome5", OleDbType.VarChar, 50);
            parameters[6].Value = t.Syndrome5;
            parameters[7] = new OleDbParameter("@syndrome6", OleDbType.VarChar, 50);
            parameters[7].Value = t.Syndrome6;
            parameters[8] = new OleDbParameter("@syndrome7", OleDbType.VarChar, 50);
            parameters[8].Value = t.Syndrome7;
            parameters[9] = new OleDbParameter("@syndrome8", OleDbType.VarChar, 50);
            parameters[9].Value = t.Syndrome8;
            parameters[10] = new OleDbParameter("@syndrome9", OleDbType.VarChar, 50);
            parameters[10].Value = t.Syndrome9;
            parameters[11] = new OleDbParameter("@syndrome10", OleDbType.VarChar, 50);
            parameters[11].Value = t.Syndrome10;
            parameters[12] = new OleDbParameter("@syndrome11", OleDbType.VarChar, 50);
            parameters[12].Value = t.Syndrome11;
            parameters[13] = new OleDbParameter("@syndrome12", OleDbType.VarChar, 50);
            parameters[13].Value = t.Syndrome12;
            parameters[14] = new OleDbParameter("@syndrome13", OleDbType.VarChar, 50);
            parameters[14].Value = t.Syndrome13;
            parameters[15] = new OleDbParameter("@syndrome14", OleDbType.VarChar, 50);
            parameters[15].Value = t.Syndrome14;
            parameters[16] = new OleDbParameter("@syndrome15", OleDbType.VarChar, 50);
            parameters[16].Value = t.Syndrome15;
            parameters[17] = new OleDbParameter("@syndrome16", OleDbType.VarChar, 50);
            parameters[17].Value = t.Syndrome16;
            parameters[18] = new OleDbParameter("@syndrome17", OleDbType.VarChar, 50);
            parameters[18].Value = t.Syndrome17;
            parameters[19] = new OleDbParameter("@syndrome18", OleDbType.VarChar, 50);
            parameters[19].Value = t.Syndrome18;
            parameters[20] = new OleDbParameter("@syndrome19", OleDbType.VarChar, 50);
            parameters[20].Value = t.Syndrome19;
            parameters[21] = new OleDbParameter("@syndrome20", OleDbType.VarChar, 50);
            parameters[21].Value = t.Syndrome20;
            parameters[22] = new OleDbParameter("@syndrome21", OleDbType.VarChar, 50);
            parameters[22].Value = t.Syndrome21;
            parameters[23] = new OleDbParameter("@syndrome22", OleDbType.VarChar, 50);
            parameters[23].Value = t.Syndrome22;
            parameters[24] = new OleDbParameter("@syndrome23", OleDbType.VarChar, 50);
            parameters[24].Value = t.Syndrome23;
            parameters[25] = new OleDbParameter("@syndrome24", OleDbType.VarChar, 50);
            parameters[25].Value = t.Syndrome24;
            parameters[26] = new OleDbParameter("@syndrome25", OleDbType.VarChar, 50);
            parameters[26].Value = t.Syndrome25;
            parameters[27] = new OleDbParameter("@syndrome26", OleDbType.VarChar, 50);
            parameters[27].Value = t.Syndrome26;
            parameters[28] = new OleDbParameter("@syndrome27", OleDbType.VarChar, 50);
            parameters[28].Value = t.Syndrome27;
            parameters[29] = new OleDbParameter("@syndrome28", OleDbType.VarChar, 50);
            parameters[29].Value = t.Syndrome28;
            parameters[30] = new OleDbParameter("@syndrome29", OleDbType.VarChar, 50);
            parameters[30].Value = t.Syndrome29;
            parameters[31] = new OleDbParameter("@syndrome30", OleDbType.VarChar, 50);
            parameters[31].Value = t.Syndrome30;
            parameters[32] = new OleDbParameter("@tongue1", OleDbType.VarChar, 50);
            parameters[32].Value = t.Tongue1;
            parameters[33] = new OleDbParameter("@tongue2", OleDbType.VarChar, 50);
            parameters[33].Value = t.Tongue2;
            parameters[34] = new OleDbParameter("@tongue3", OleDbType.VarChar, 100);
            parameters[34].Value = t.Tongue3;
            parameters[35] = new OleDbParameter("@pulse", OleDbType.VarChar, 255);
            parameters[35].Value = t.Pulse;
            parameters[36] = new OleDbParameter("@differentiation", OleDbType.VarChar, 50);
            parameters[36].Value = t.Differentiation;
            parameters[37] = new OleDbParameter("@conclusion", OleDbType.VarChar, 50);
            parameters[37].Value = t.Conclusion;
            parameters[38] = new OleDbParameter("@id", OleDbType.Integer);
            parameters[38].Value = t.Id;


            return AccessDBUtil.ExecuteNonQuery(sql, parameters);


        }
        public static TCM getById(int id)
        {
            string sql = "select * from tcm where id=?";
            OleDbParameter[] parameters = new OleDbParameter[1];
            parameters[0] = new OleDbParameter("@id", OleDbType.Integer);
            parameters[0].Value = id;
            DataSet ds = AccessDBUtil.ExecuteQuery(sql, parameters);

            if (ds.Tables["ds"].Rows.Count > 0)
            {
                return Row2TCM(ds.Tables["ds"].Rows[0]);
            } return null;
        }


        private static TCM Row2TCM(DataRow row)
        {
            TCM t = new TCM();
            t.Id = Int32.Parse(row["id"].ToString());
            t.PatientId = Int32.Parse(row["patient_id"].ToString());
            t.CreateDate = DateTime.Parse(row["create_date"].ToString());
            t.Syndrome1 = row["syndrome1"].ToString();
            t.Syndrome2 = row["syndrome2"].ToString();
            t.Syndrome3 = row["syndrome3"].ToString();
            t.Syndrome4 = row["syndrome4"].ToString();
            t.Syndrome5 = row["syndrome5"].ToString();
            t.Syndrome6 = row["syndrome6"].ToString();
            t.Syndrome7 = row["syndrome7"].ToString();
            t.Syndrome8 = row["syndrome8"].ToString();
            t.Syndrome9 = row["syndrome9"].ToString();
            t.Syndrome10 = row["syndrome10"].ToString();
            t.Syndrome11 = row["syndrome11"].ToString();
            t.Syndrome12 = row["syndrome12"].ToString();
            t.Syndrome13 = row["syndrome13"].ToString();
            t.Syndrome14 = row["syndrome14"].ToString();
            t.Syndrome15 = row["syndrome15"].ToString();
            t.Syndrome16 = row["syndrome16"].ToString();
            t.Syndrome17 = row["syndrome17"].ToString();
            t.Syndrome18 = row["syndrome18"].ToString();
            t.Syndrome19 = row["syndrome19"].ToString();
            t.Syndrome20 = row["syndrome20"].ToString();
            t.Syndrome21 = row["syndrome21"].ToString();
            t.Syndrome22 = row["syndrome22"].ToString();
            t.Syndrome23 = row["syndrome23"].ToString();
            t.Syndrome24 = row["syndrome24"].ToString();
            t.Syndrome25 = row["syndrome25"].ToString();
            t.Syndrome26 = row["syndrome26"].ToString();
            t.Syndrome27 = row["syndrome27"].ToString();
            t.Syndrome28 = row["syndrome28"].ToString();
            t.Syndrome29 = row["syndrome29"].ToString();
            t.Syndrome30 = row["syndrome30"].ToString();
            t.Tongue1 = row["tongue1"].ToString();
            t.Tongue2 = row["tongue2"].ToString();
            t.Tongue3 = row["tongue3"].ToString();
            t.Pulse = row["pulse"].ToString();
            t.Differentiation = row["differentiation"].ToString();
            t.Conclusion = row["conclusion"].ToString();

            return t;
        }

        public static int getTCMCountByDate(int patient_id, DateTime create_date)
        {
            string sql = "select * from TCM where patient_id=? and create_date=?";
            OleDbParameter[] parameters = new OleDbParameter[2];
            parameters[0] = new OleDbParameter("@patient_id", OleDbType.Integer);
            parameters[0].Value = patient_id;
            parameters[1] = new OleDbParameter("@is_first", OleDbType.Date);
            parameters[1].Value = create_date;
            DataSet ds = AccessDBUtil.ExecuteQuery(sql, parameters);
            return ds.Tables["ds"].Rows.Count;

        }
    }
}
